var mysql = require("mysql");
var config = require("../config/setting.js");

var connection = null;

var getConnection = function () {
    if (!connection) {
        var currentEnv = global.CURRENT_ENV ? global.CURRENT_ENV : 'production';
        connection = mysql.createConnection(config['db'][currentEnv]);
        console.info('current env is %s, success to connect db.', currentEnv);
    }
    return connection;
};


module.exports = getConnection;